<template>
	<a-modal
		v-model:open="visible"
		:title="title"
		:width="500"
		@ok="handleOk"
		@cancel="handleCancel"
		:confirm-loading="confirmLoading"
	>
		<a-form ref="formRef" layout="vertical">
			<a-form-item name="remark">
				<a-textarea
					v-model:value="remark"
					:placeholder="'请输入' + title + '备注'"
					:auto-size="{ minRows: 3, maxRows: 6 }"
				/>
			</a-form-item>
		</a-form>
	</a-modal>
</template>

<script setup>
	import assetsIssueApi from '@/api/hrms/assets/issue/assetsIssueApi'

	// 定义事件
	const emit = defineEmits(['confirm'])
	const title = ref('')
	// 表单引用
	const formRef = ref()

	// 模态框可见性
	const visible = ref(false)

	// 确认按钮加载状态
	const confirmLoading = ref(false)

	const issueId = ref()
	const issueStatus = ref()

	// 表单数据
	const remark = ref('')

	const show = (id, status, titleText) => {
		visible.value = true
		issueId.value = id
		issueStatus.value = status
		title.value = titleText
	}

	// 确认操作
	const handleOk = async () => {
		confirmLoading.value = true
		await assetsIssueApi.operation(issueId.value, issueStatus.value, remark.value).catch((error) => {
			console.error('提交失败:', error)
		})
		confirmLoading.value = false
		visible.value = false
		emit('confirm')
	}

	// 取消操作
	const handleCancel = () => {
		emit('cancel')
		visible.value = false
		remark.value = ''
	}

	// 暴露方法给父组件
	defineExpose({
		show
	})
</script>
